package cn.stylefeng.guns.modular.rest.agv;

import cn.stylefeng.guns.modular.agv.entity.RoadWayListRsVo;
import cn.stylefeng.guns.modular.agv.model.params.*;
import cn.stylefeng.guns.modular.agv.model.result.HikAgvRoadWayJLResult;
import cn.stylefeng.guns.modular.agv.model.result.HikAgvRoadWayResult;
import cn.stylefeng.guns.modular.agv.model.result.HikAgvTaskJLResult;
import cn.stylefeng.guns.modular.agv.model.result.HikAgvTaskResult;
import cn.stylefeng.guns.modular.agv.service.HikAgvRoadWayJlService;
import cn.stylefeng.guns.modular.agv.service.HikAgvRoadWayService;
import cn.stylefeng.guns.modular.agv.service.HikAgvTaskJLService;
import cn.stylefeng.guns.modular.agv.service.HikAgvTaskService;
import cn.stylefeng.guns.modular.agv.util.HikBackRsVo;
import cn.stylefeng.guns.modular.rest.aop.UserAop;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
import java.util.List;

/**
 *地址控制器
 */
@Controller
@RequestMapping("/rest/hikAgvTaskController")
public class RestHikAgvTaskController extends BaseController {

    @Autowired
    private UserAop userAop;

    @Autowired
    private HikAgvTaskService hikAgvTaskService;

    @Autowired
    private HikAgvTaskJLService hikAgvTaskJlService;

    @Autowired
    private HikAgvRoadWayService hikAgvRoadWayService;

    @Autowired
    private HikAgvRoadWayJlService hikAgvRoadWayJlService;


    /**
     * 新增接口
     *
     * @author zhangzh
     * @Date 2024-05-14
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(HikAgvTaskParam hikAgvTaskParam) {
        User user = userAop.getUser();
        if(user !=null && user.getUserId() != null){
            //创建人
            hikAgvTaskParam.setCreateUser(user.getUserId());
        }
        //创建时间
        hikAgvTaskParam.setCreateTime(new Date());
        hikAgvTaskParam.setUpdateTime(new Date());

        if( hikAgvTaskParam.getTaskTyp() == null || "".equals(hikAgvTaskParam.getTaskTyp())){
            hikAgvTaskParam.setTaskTyp("F14");
        }

        if( hikAgvTaskParam.getCtnrTyp() == null || "".equals(hikAgvTaskParam.getCtnrTyp())){
            hikAgvTaskParam.setCtnrTyp("1");
        }
        hikAgvTaskParam.setStat("01");
        hikAgvTaskParam.setSrcPositionType("00");
        hikAgvTaskParam.setTarPositionType("06");
        return hikAgvTaskService.addTask(hikAgvTaskParam);
    }

    /**
     * 新增接口长春一期
     *
     * @author lww
     * @Date 2024-10-22
     */
    @RequestMapping("/addItemcc")
    @ResponseBody
    public ResponseData addItemcc(HikAgvTaskJLParam hikAgvTaskJLParam) {
        User user = userAop.getUser();
        if(user !=null && user.getUserId() != null){
            //创建人
            hikAgvTaskJLParam.setCreateUser(user.getUserId());
        }
        //创建时间
        hikAgvTaskJLParam.setCreateTime(new Date());
        hikAgvTaskJLParam.setUpdateTime(new Date());

        if( hikAgvTaskJLParam.getTaskTyp() == null || "".equals(hikAgvTaskJLParam.getTaskTyp())){
            hikAgvTaskJLParam.setTaskTyp("F14");
        }

        if( hikAgvTaskJLParam.getCtnrTyp() == null || "".equals(hikAgvTaskJLParam.getCtnrTyp())){
            hikAgvTaskJLParam.setCtnrTyp("1");
        }
        hikAgvTaskJLParam.setStat("01");
        hikAgvTaskJLParam.setSrcPositionType("00");
        hikAgvTaskJLParam.setTarPositionType("06");
        hikAgvTaskJLParam.setDeptId(user.getDeptId().toString());
        return hikAgvTaskJlService.addTaskcc(hikAgvTaskJLParam);
    }
    /**
     * 设置优先级
     * @param hikAgvTaskParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/setPriority")
    public ResponseData setPriority(HikAgvTaskParam hikAgvTaskParam) {
        return this.hikAgvTaskService.setPriority(hikAgvTaskParam);
    }
    /**
     * 设置优先级
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/setPriorityJL")
    public ResponseData setPriorityJL(HikAgvTaskJLParam hikAgvTaskJLParam) {
        return this.hikAgvTaskJlService.setPriority(hikAgvTaskJLParam);
    }
    /**
     * 清空通道
     * @param roadWayCode
     * @return
     */
    @ResponseBody
    @RequestMapping("/clear")
    public ResponseData clear(String roadWayCode) {
        return this.hikAgvTaskService.clear(roadWayCode);
    }

    @ResponseBody
    @RequestMapping("/cancelTask")
    public ResponseData cancelTask(String taskCode) {
        return this.hikAgvTaskService.cancelTask(taskCode);
    }

    @ResponseBody
    @RequestMapping("/cancelTaskJL")
    public ResponseData cancelTaskJL(String taskCode) {
        return this.hikAgvTaskJlService.cancelTask(taskCode);
    }

    /**
     *
     * @param hiKAgvCallbackParm
     * @return
     */
    @ResponseBody
    @RequestMapping("/agvCallback")
    public HikBackRsVo agvCallback(@RequestBody HiKAgvCallbackParm hiKAgvCallbackParm) {
        HikBackRsVo hikRsVo = new HikBackRsVo();
        hikRsVo.setCode("0");
        hikRsVo.setMessage("成功");
        hikRsVo.setReqCode(hiKAgvCallbackParm.getReqCode());
        hikAgvTaskService.agvCallback(hiKAgvCallbackParm);
        return hikRsVo;
    }

    @ResponseBody
    @RequestMapping("/storage/agvCallback")
    public HikBackRsVo agvStorageCallback(@RequestBody HiKAgvCallbackParm hiKAgvCallbackParm) {
        HikBackRsVo hikRsVo = new HikBackRsVo();
        hikRsVo.setCode("0");
        hikRsVo.setMessage("成功");
        hikRsVo.setReqCode(hiKAgvCallbackParm.getReqCode());
        hikAgvTaskService.agvStorageCallback(hiKAgvCallbackParm);
        return hikRsVo;
    }
    /**
     *
     * @param hiKAgvCallbackParm
     * @return长春一期
     */
    @ResponseBody
    @RequestMapping("/agvCallbackJL")
    public HikBackRsVo agvCallbackJL(@RequestBody HiKAgvCallbackParm hiKAgvCallbackParm) {
        HikBackRsVo hikRsVo = new HikBackRsVo();
        hikRsVo.setCode("0");
        hikRsVo.setMessage("成功");
        hikRsVo.setReqCode(hiKAgvCallbackParm.getReqCode());
        hikAgvTaskJlService.agvCallback(hiKAgvCallbackParm);
        return hikRsVo;
    }
    @ResponseBody
    @RequestMapping("/listAll")
    public List<HikAgvTaskResult> listAll(HikAgvTaskParam hikAgvTaskParam ) {
        hikAgvTaskParam.setStat("01");
        return this.hikAgvTaskService.findListBySpec(hikAgvTaskParam);
    }

    @ResponseBody
    @RequestMapping("/RoadWayListAll")
    public List<HikAgvRoadWayResult> RoadWayListAll(HikAgvRoadWayParam param ) {
        return this.hikAgvRoadWayService.findListBySpec(param);
    }
    @ResponseBody
    @RequestMapping("/listJL")
    public List<HikAgvTaskJLResult> listAllCC(HikAgvTaskJLParam hikAgvTaskJLParam ) {
        hikAgvTaskJLParam.setStat("01");
        List<HikAgvTaskJLResult> listBySpec = this.hikAgvTaskJlService.findListBySpec(hikAgvTaskJLParam);
        return listBySpec;
    }
    @ResponseBody
    @RequestMapping("/RoadWayListAllJL")
    public List<HikAgvRoadWayJLResult> RoadWayListAll(HikAgvRoadWayJLParam param ) {
        return this.hikAgvRoadWayJlService.findListBySpec(param);
    }
    /**
     * 清空通道
     * @param roadWayCode
     * @return
     */
    @ResponseBody
    @RequestMapping("/clearJL")
    public ResponseData clearJL(String roadWayCode) {
        return this.hikAgvTaskJlService.clear(roadWayCode);
    }

    @ResponseBody
    @RequestMapping("/RoadWayQuery")
    public List<RoadWayListRsVo> RoadWayQuery(RoadWayListParam param ) {
        return this.hikAgvRoadWayService.reestRoadWayList(param);
    }


}
